﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PPAP.BO;

namespace PPAP.Web.Report
{
    public partial class DistributionReport : PageBase
    {
        LogBO bo = new LogBO();
        UsersBO ubo = new UsersBO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Search();
                DataSet ds = ubo.GetQE();
                ddlUsers.Items.Add(new ListItem("All", "All"));
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ddlUsers.Items.Add(new ListItem(dr["username"].ToString(), dr["username"].ToString()));
                }
                Search();
            }
        }

        private void Search()
        {
            
            //if ((txtStart.Text.Trim() != "" && txtEnd.Text.Trim() == ""))
            //{
            //    AlertMessage("Please choose the end time");
            //    return;
            //}
            //if (txtEnd.Text.Trim() != "" && txtStart.Text.Trim() == "")
            //{
            //    AlertMessage("Please choose the start time");
            //    return;
            //}
            string date1 = txtStart.Text.Trim() == "" ? null : txtStart.Text.Trim();
            string date2 = txtEnd.Text.Trim() == "" ? null : txtEnd.Text.Trim();

            DataSet ds = null;
                ds = bo.GetReportForDistribution(date1, date2,ddlUsers.SelectedValue);
            DataView dv = new DataView(ds.Tables[0]);
            Chart1.Series[0].Points.DataBindXY(dv, "name", dv, "count");
            

            dgList.DataSource = ds;
            dgList.DataBind();

            //Label1.Text = "<table cellspacing='0' cellpadding='4' border='0'  style='color:#333333;width:800px;border-collapse:collapse;'>";
            //Label1.Text += "<tr style='color:Black;background-color:#E7E8E8;font-weight:bold;'><th scope='col'>Name</th>";
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Label1.Text += "<th scope='col'>" + dr["cw"].ToString() + "</th>";
            //}
            //Label1.Text += "</tr>";
            //Label1.Text += "<tr style='background-color:#EFF3FB;'><td align='center'><font color='red'>Refused</font></td>";
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Label1.Text += "<td  align='center'>" + dr["c1"].ToString() + "</td>";
            //}
            //Label1.Text += "</tr>";
            //Label1.Text += "<tr style='background-color:White;'><td align='center'><font color='Yellow'>conditionally approved</font></td>";
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Label1.Text += "<td  align='center'>" + dr["c2"].ToString() + "</td>";
            //}
            //Label1.Text += "</tr>";
            //Label1.Text += "<tr style='background-color:#EFF3FB;'><td align='center'><font color='Lime'>approved</font></td>";
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Label1.Text += "<td  align='center'>" + dr["c3"].ToString() + "</td>";
            //}
            //Label1.Text += "</tr>";
            //Label1.Text += "<tr style='background-color:White;'><td align='center'><font color='Teal'>No. of parts arrived for inspection</font></td>";
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Label1.Text += "<td  align='center'>" + dr["c4"].ToString() + "</td>";
            //}
            //Label1.Text += "</tr>";
            //Label1.Text += "<tr style='background-color:#EFF3FB;'><td align='center'><font color='Black'>No. of inspection started</font></td>";
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Label1.Text += "<td  align='center'>" + dr["c5"].ToString() + "</td>";
            //}
            //Label1.Text += "</tr>";
            //Label1.Text += "<tr style='background-color:White;'><td align='center'><font color='Cyan'>No. of inspection finished</font></td>";
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Label1.Text += "<td  align='center'>" + dr["c6"].ToString() + "</td>";
            //}
            //Label1.Text += "</tr>";
            //Label1.Text += "<tr style='background-color:#EFF3FB;'><td align='center'><font color='Blue'>Planed no of inspection  finished </font></td>";
            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    Label1.Text += "<td  align='center'>" + dr["c7"].ToString() + "</td>";
            //}
            //Label1.Text += "</tr>";

            //Label1.Text += "</table>";
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Search();
        }
    }
}